<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no">
    <meta name="format-detection" content="telephone=no" />
    <meta name="format-detection" content="email=no">
    <meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <meta HTTP-EQUIV="Expires" CONTENT="0">
    <!-- import CSS -->
    <title>登录界面</title>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <link rel="stylesheet" type="text/css" href="css/login.css" />
    <link rel="stylesheet" href="../common/css/animate.min.css" />

</head>

<body>
    <div id="app">
        <h1>毅瑭科技</h1>
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="账号" prop="mobile">
                <el-input v-model="ruleForm.mobile"></el-input>
            </el-form-item>


            <el-form-item label="密码" prop="password">
                <el-input type="password" v-model="ruleForm.password"></el-input>
            </el-form-item>





            <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')">登录
                </el-button>
            </el-form-item>
        </el-form>
    </div>

</body>
<script src="../common/js/api/vue3-axios-utils.js"></script>
<!-- import Vue before Element -->
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>


<script>
    new Vue({
        el: '#app',
        data() {
            return {
                ruleForm: {
                    mobile: '',
                    password: '',

                },

                rules: {
                    mobile: [
                        { required: true, message: '请输入您的账号', trigger: 'blur' },
                        { min: 2, max: 20, message: '请输入正确的账号', trigger: 'blur' }
                    ],
                    password: [
                        { required: true, message: '请输入您的密码', trigger: 'blur' },
                        { min: 2, max: 20, message: '请输入正确的密码', trigger: 'blur' }
                    ]


                }
            };
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        axios.post(spliceUrl('/sys/phonePwdLogin'), {
                            mobile: this.ruleForm.mobile,
                            password: this.ruleForm.password
                        }).then(response => {

                            // console.log(response);
                            // alert(response.data.code);
                            if (response.data.code && response.data.code == 200) {
                                // const token = store.getters.token;
                                // alert(token);
                                // window.location.href = './patientList.html'
                                alert('登录成功');
                                localStorage.setItem("token", response.data.result.token);
                                window.open('./patientList.html')
                                // window.location.href = './patientList.html';
                                console.log(response.data.result.token);
                            } else {
                                alert('账号不存在或账号密码存在错误！')
                            }
                        }).catch(error => {
                            alert('登录失败');
                        })

                    }
                });
            },


        }

    })
</script>

</html>